<%--
  Created by IntelliJ IDEA.
  User: 联想
  Date: 2020/2/21
  Time: 12:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>学生登陆</title>

    <!-- Custom fonts for this template-->
    <link href="${pageContext.request.contextPath}/static/stuLogin/vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
    <link href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i" rel="stylesheet">

    <!-- Custom styles for this template-->
    <link href="${pageContext.request.contextPath}/static/stuLogin/css/sb-admin-2.min.css" rel="stylesheet">

</head>

<script src="/js/jquery-3.3.1.js"></script>
<script>
    function checkUsername() {
        //1.获取用户名值
        var username = $("#studentNo").val();
        //2.定义正则
        var reg_username = /^\w{9}$/;

        //3.判断，给出提示信息
        var flag = reg_username.test(username);
        if(flag){
            //用户名合法
            $("#studentNo").css("border","2px solid green");
            $("#NoSpan").css("color","green")
            $("#NoSpan").html("符合要求");
        }else{
            //用户名非法,加一个红色边框
            $("#studentNo").css("border","2px solid red");
            $("#NoSpan").css("color","red")
            $("#NoSpan").html("请输入长度为9位数的学号");
        }

        return flag;
    }

    //校验密码
    function checkPassword() {
        //1.获取密码值
        var password = $("#studentPwd").val();
        //2.定义正则
        var reg_password = /^\w{8,20}$/;

        //3.判断，给出提示信息
        var flag = reg_password.test(password);
        if(flag){
            //密码合法
            $("#studentPwd").css("border","2px solid green");
            $("#PwdSpan").css("color","green")
            $("#PwdSpan").html("符合要求");
        }else{
            //密码非法,加一个红色边框
            $("#studentPwd").css("border","2px solid red");
            $("#PwdSpan").css("color","red")
            $("#PwdSpan").html("请输入8-20长度的密码");
        }

        return flag;
    }

    //校验验证码
    function checkCode(){
        //1.获取验证码
        var code = $("#checkCode").val();

        if(code != ''){
            $("#checkCode").css("border","");
            return true;
        }else{
            $("#checkCode").css("border","2px solid red");
            $("#CodeSpan").css("color","red")
            $("#CodeSpan").html("验证码不能为空");
            return false;
        }
    }
    $(function () {
        //当表单提交时，调用所有的校验方法
        $("#loginForm").submit(function(){
            //1.发送数据到服务器
            if(checkUsername() && checkPassword() && checkCode()){
                //校验通过,发送ajax请求，提交表单的数据   username=zhangsan&password=123
                //window.location.href = "${pageContext.request.contextPath}/student/register";
                return true;
            }
            //2.不让页面跳转
            return false;
            //如果这个方法没有返回值，或者返回为true，则表单提交，如果返回为false，则表单不提交
        });
        //当某一个组件失去焦点是，调用对应的校验方法
        $("#studentNo").blur(checkUsername);
        $("#studentPwd").blur(checkPassword);
        $("#checkCode").blur(checkCode);
    });
</script>

<body class="bg-gradient-primary">

<div class="container">

    <!-- Outer Row -->
    <div class="row justify-content-center">

        <div class="col-xl-10 col-lg-12 col-md-9">

            <div class="card o-hidden border-0 shadow-lg my-5">
                <div class="card-body p-0">
                    <!-- Nested Row within Card Body -->
                    <div class="row">
                        <div class="col-lg-6 d-none d-lg-block bg-login-image"></div>
                        <div class="col-lg-6">
                            <div class="p-5">
                                <div class="text-center">
                                    <h1 class="h4 text-gray-900 mb-4">Welcome Back!</h1>
                                </div>
                                <form class="user" action="${pageContext.request.contextPath}/student/login" method="get" id="loginForm">
                                    <div class="form-group">
                                        <input type="text" class="form-control form-control-user" id="studentNo" name="studentNo" placeholder="学号">
                                        <span id="NoSpan"></span>
                                    </div>
                                    <div class="form-group">
                                        <input type="password" class="form-control form-control-user" id="studentPwd" name="studentPwd" placeholder="密码">
                                        <span id="PwdSpan"></span>
                                    </div>
                                    <div class="form-group row">
                                        <div class="col-sm-6 mb-3 mb-sm-0">
                                            <input type="text" class="form-control form-control-user" id="checkCode" name="checkCode" placeholder="验证码">
                                            <span id="CodeSpan"></span>
                                        </div>
                                        <div class="col-sm-6">
                                            <img src="${pageContext.request.contextPath}/CheckCode" height="32px" alt="" onclick="changeCheckCode(this)"/>
                                            <script type="text/javascript">
                                                //图片点击事件
                                                function changeCheckCode(img) {
                                                    img.src = "${pageContext.request.contextPath}/CheckCode?" + new Date().getTime();
                                                }
                                            </script>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="custom-control custom-checkbox small">
                                            <input type="checkbox" class="custom-control-input" id="customCheck">
                                            <label class="custom-control-label" for="customCheck">Remember Me</label>
                                        </div>
                                    </div>
                                    <button type="submit" class="btn btn-primary btn-user btn-block">
                                        Login
                                    </button>
                                    <hr>
                                    <a href="#" class="btn btn-google btn-user btn-block">
                                        <i class="fab fa-google fa-fw"></i> Login with Google
                                    </a>
                                    <a href="#" class="btn btn-facebook btn-user btn-block">
                                        <i class="fab fa-facebook-f fa-fw"></i> Login with Facebook
                                    </a>
                                </form>
                                <hr>
                                <div class="text-center">
                                    <a class="small" href="#"><span style="color:red;">${loginErrorMsg}</span>
                                        <span style="color:red;">${checkMsg}</span></a>
                                </div>
                                <div class="text-center">
                                    <a class="small" href="${pageContext.request.contextPath}/student/toForgetPwd">Forgot Password?</a>
                                </div>
                                <div class="text-center">
                                    <a class="small" href="${pageContext.request.contextPath}/student/goRegister">Create an Account!</a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>

    </div>

</div>

<!-- Bootstrap core JavaScript-->
<script src="${pageContext.request.contextPath}/static/stuLogin/vendor/jquery/jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/static/stuLogin/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

<!-- Core plugin JavaScript-->
<script src="${pageContext.request.contextPath}/static/stuLogin/vendor/jquery-easing/jquery.easing.min.js"></script>

<!-- Custom scripts for all pages-->
<script src="${pageContext.request.contextPath}/static/stuLogin/js/sb-admin-2.min.js"></script>

</body>
</html>